package com.jg.myproject.module.home;

import android.content.Intent;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.jg.myproject.WelcomeActitivy;
import com.jg.myproject.adapter.HomeAdapter;
import com.jg.myproject.api.Const;
import com.jg.myproject.api.bean.BaseEntity;
import com.jg.myproject.api.bean.reponse.CommonReponseBean;
import com.jg.myproject.api.entity.HomeItem;
import com.jg.myproject.module.actualtime.ActualTimeDataActivity;
import com.jg.myproject.module.base.BaseActivity;
import com.jg.myproject.module.checkpoint.CheckPointActivity;
import com.jg.myproject.module.deviceinfo.DeviceInfoActivity;
import com.jg.myproject.module.historydata.HistoryTimeDataActivity;
import com.jg.myproject.module.projectinfo.ProjectInfoActivity;
import com.jg.myproject.module.warninfo.WarnInfoActivity;
import com.jg.myproject.utils.RxSPTool;
import com.jg.myproject.widget.HomeDividerItemDecoration;
import com.zcr.myproject.R;

import java.util.ArrayList;


/**
 * Created by llz on 2018/3/29.
 */

public  class HomeActivity extends BaseActivity {

    private static final Class<?>[] ACTIVITY = {ActualTimeDataActivity.class, HistoryTimeDataActivity.class, WarnInfoActivity.class, ProjectInfoActivity.class, CheckPointActivity.class, DeviceInfoActivity.class};
    private static final String[] TITLE = {"实时数据", "历史数据", "警报信息", "工程信息", "测点分布", "设备信息"};
    private static final int[] IMG = {R.drawable.home_button_sssj_default_01, R.drawable.home_button_lssjj_default_02, R.drawable.home_button_bjxx_default_03, R.drawable.home_button_gcxx_default_04, R.drawable.home_button_cdfb_default_05, R.drawable.home_button_sbxx_default_06};
    private ArrayList<HomeItem> mDataList;
    private RecyclerView mRecyclerView;

    @Override
    protected int attachLayoutRes() {
        return R.layout.home_activity;
    }
    @Override
    protected void initViews() {
        initTitle(true,RxSPTool.getString(this,Const.PROJECTNAME));
        mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
        mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
        //添加Android自带的分割线
        mRecyclerView.addItemDecoration(new HomeDividerItemDecoration(this));
        mDataList = new ArrayList<>();
        for (int i = 0; i < TITLE.length; i++) {
            HomeItem item = new HomeItem();
            item.setTitle(TITLE[i]);
            item.setActivity(ACTIVITY[i]);
            item.setImageResource(IMG[i]);
            mDataList.add(item);
        }
        initAdapter();
    }
    @Override
    protected void updateViews(boolean isRefresh) {
    }

    private void initAdapter() {
        BaseQuickAdapter homeAdapter = new HomeAdapter(R.layout.home_item_view, mDataList);
        View top = getLayoutInflater().inflate(R.layout.top_view, (ViewGroup) mRecyclerView.getParent(), false);
        homeAdapter.addHeaderView(top);
        homeAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                Intent intent = new Intent(HomeActivity.this, ACTIVITY[position]);
                startActivity(intent);
            }
        });
        mRecyclerView.setAdapter(homeAdapter);
    }

    @Override
    public void getReponseBeans(BaseEntity<CommonReponseBean> bean) {
    }
}
